package com.blank.shop.ssr.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <br/>Date 2021/9/8
 * <br/>Time 13:34:04
 *
 * @author _blank
 */
public class TestController {

    @Slf4j
    @RestController
    public static class Aa {
        /**
         * @see org.springframework.web.servlet.FrameworkServlet#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 先设置到threadlocal
         * @see org.springframework.web.context.support.WebApplicationContextUtils.RequestObjectFactory#getObject()
         * @see org.springframework.web.context.support.WebApplicationContextUtils#registerWebApplicationScopes(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, javax.servlet.ServletContext) 再从threadlocal获取当前的request
         */
        @Resource
        private HttpServletRequest httpServletRequest;

        @GetMapping(path = {"t1"})
        public void sayHello(String p1) {
            final String p11 = this.httpServletRequest.getParameter("p1");
            log.info("{}    {}    {}", this.httpServletRequest.hashCode(), p11, p1);
        }

    }

    @Slf4j
    @RestController
    public static class Bb {
        @Resource
        private HttpServletRequest httpServletRequest;

        @GetMapping(path = {"t2"})
        public void sayHello(String p2) {
            final String p21 = this.httpServletRequest.getParameter("p2");
            log.info("{}    {}    {}", this.httpServletRequest.hashCode(), p21, p2);
        }

    }

}
